import pymysql

class MysqlUtil:
    @classmethod
    def getCONNECT(cls):
        myconn=pymysql.connect(host="211.103.136.244",
                               port=7061,
                               user="student",
                               password="iHRM_student_2022",
                               database="ihrm",
                               charset="utf8")
        return myconn
    @classmethod
    def select(cls):
        myconn=None
        mycursor=None
        data=None
        try:
            myconn=MysqlUtil.getCONNECT()
            mycursor=myconn.cursor()
            mycursor.execute()
            data=mycursor.fetchall()
        except Exception as result:
            print("执行异常",str(result))
        else:
            print(data)
        finally:
            mycursor.close()
            myconn.close()
            print("查询结束")

    @classmethod
    def idu(cls,sql):
        myconn=None
        mycursor=None
        data=None
        try:
            myconn=MysqlUtil.getCONNECT()
            mycursor=myconn.cursor()
            data=mycursor.execute(sql)

            myconn.commit()

        except Exception as result:
            print("执行异常",str(result))
        else:
            print(data)
            myconn.rollback()

        finally:
            mycursor.close()
            myconn.close()
            print("查询结束")

